home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 2003 August / MW 8 2003 CD1.iso / Inside Macworld / Product News / gimp-1.2.4.sit / gimp-1.2.4 / plug-ins / script-fu / scripts / alien-glow-button.scm < prev    next >
Encoding:
Text File  |  2003-05-19  |  4.7 KB  |  143 lines

  1. ; The GIMP -- an image manipulation program
  2. ; Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3. ; Alien Glow themed button
  4. ; Copyright (c) 1997 Adrian Likins
  5. ; aklikins@eos.ncsu.edu
  6. ;
  7. ; based on code from Frederico Mena Quintero (Quartic)
  8. ; federico@nuclecu.unam.mx
  9. ;
  10. ; This program is free software; you can redistribute it and/or modify
  11. ; it under the terms of the GNU General Public License as published by
  12. ; the Free Software Foundation; either version 2 of the License, or
  13. ; (at your option) any later version.
  14. ; This program is distributed in the hope that it will be useful,
  15. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. ; GNU General Public License for more details.
  18. ; You should have received a copy of the GNU General Public License
  19. ; along with this program; if not, write to the Free Software
  20. ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  
  22.  
  23. (define (text-width extents)
  24.   (car extents))
  25.  
  26. (define (text-height extents)
  27.   (cadr extents))
  28.  
  29. (define (text-ascent extents)
  30.   (caddr extents))
  31.  
  32. (define (text-descent extents)
  33.   (cadr (cddr extents)))
  34.  
  35. (define (blend-bumpmap img drawable x1 y1 x2 y2)
  36.   (gimp-blend drawable
  37.           FG-BG-RGB
  38.           DARKEN-ONLY
  39.           LINEAR
  40.           100
  41.           0
  42.           REPEAT-NONE
  43.           FALSE
  44.           0
  45.           0
  46.           x1
  47.           y1
  48.           x2
  49.           y2))
  50.  
  51. (define (script-fu-alien-glow-button text
  52.                 font
  53.                 size
  54.                 text-color
  55.                 glow-color
  56.                 bg-color
  57.                 padding
  58.                 glow-radius
  59.                 flatten)
  60.   (let* ((old-fg-color (car (gimp-palette-get-foreground)))
  61.      (old-bg-color (car (gimp-palette-get-background)))
  62.      (text-extents (gimp-text-get-extents-fontname text
  63.                                size
  64.                                PIXELS
  65.                                font))
  66.      (ascent (text-ascent text-extents))
  67.      (descent (text-descent text-extents))
  68.      
  69.      (img-width (+ (* 2  padding)
  70.                (text-width text-extents)))
  71.      (img-height (+ (* 2 padding)
  72.             (+ ascent descent)))
  73.      (layer-height img-height)
  74.      (layer-width img-width)
  75.      (img-width (+ img-width glow-radius))
  76.      (img-height (+ img-height glow-radius))
  77.      (img (car (gimp-image-new  img-width   img-height  RGB)))
  78.      (bg-layer (car (gimp-layer-new img img-width img-height RGBA_IMAGE "Background" 100 NORMAL)))
  79.      (glow-layer (car (gimp-layer-new img img-width img-height RGBA_IMAGE "Glow" 100 NORMAL)))
  80.      (button-layer (car (gimp-layer-new img layer-width layer-height RGBA_IMAGE "Button" 100 NORMAL))))
  81.  
  82.     (gimp-image-undo-disable img)
  83.  
  84.     ; Create bumpmap layer
  85.     
  86.     (gimp-image-add-layer img bg-layer -1)
  87.     (gimp-palette-set-foreground '(0 0 0))
  88.     (gimp-palette-set-background bg-color)
  89.     (gimp-edit-fill bg-layer BG-IMAGE-FILL)
  90.     (gimp-image-add-layer img glow-layer -1)
  91.  
  92.     ; Create text layer
  93.  
  94.     (gimp-image-add-layer img button-layer -1)
  95.     (gimp-layer-set-offsets button-layer (/ glow-radius 2) (/ glow-radius 2))
  96.     (gimp-selection-none img)
  97.     (gimp-rect-select img 0 0 img-width img-height REPLACE FALSE 0)
  98.     (gimp-palette-set-foreground '(100 100 100))
  99.     (gimp-palette-set-background '(0 0 0))
  100.     (gimp-blend button-layer FG-BG-RGB NORMAL SHAPEBURST-ANGULAR 100 0 REPEAT-NONE FALSE 0 0 0 0 img-height img-width)
  101.     (gimp-edit-clear glow-layer)
  102.     (gimp-rect-select img (/ glow-radius 4) (/ glow-radius 4) (- img-width (/ glow-radius 2)) (- img-height (/ glow-radius 2)) REPLACE FALSE 0 )
  103.     (gimp-palette-set-foreground glow-color)
  104.     (gimp-edit-fill glow-layer FG-IMAGE-FILL)
  105.     (gimp-selection-none img)
  106.     (plug-in-gauss-rle 1 img glow-layer glow-radius TRUE TRUE)
  107.     (gimp-palette-set-foreground text-color)
  108.     (let ((textl (car (gimp-text-fontname
  109.                img -1 0 0 text 0 TRUE size PIXELS font))))
  110.       (gimp-layer-set-offsets textl
  111.                   (+  padding (/ glow-radius 2))
  112.                   (+ (+ padding descent) (/ glow-radius 2))))
  113.     ; Done
  114.     (gimp-selection-none img)
  115.     (gimp-palette-set-foreground old-fg-color)
  116.     (gimp-palette-set-background old-bg-color)
  117.     (gimp-image-undo-enable img)
  118.     (if (= flatten TRUE)
  119.     (gimp-image-flatten img))
  120.     (gimp-display-new img)))
  121.  
  122. ; Register!
  123.  
  124. (script-fu-register "script-fu-alien-glow-button"
  125.             _"<Toolbox>/Xtns/Script-Fu/Web Page Themes/Alien Glow/Button..."
  126.             "Button with an eerie glow"
  127.             "Adrian Likins"
  128.             "Adrian Likins"
  129.             "July 1997"
  130.             ""
  131.             SF-STRING _"Text" "Hello world!"
  132.             SF-FONT   _"Font" "-*-futura_poster-*-*-*-*-22-*-*-*-*-*-*-*"
  133.             SF-ADJUSTMENT _"Font Size (pixels)" '(22 2 100 1 1 0 1)
  134.             SF-COLOR      _"Text Color" '(0 0 0)
  135.             SF-COLOR      _"Glow Color" '(63 252 0)
  136.             SF-COLOR      _"Background Color" '(0 0 0)
  137.             SF-ADJUSTMENT _"Padding" '(6 1 100 1 10 0 1)
  138.             SF-ADJUSTMENT _"Glow Radius" '(10 1 200 1 10 0 1)
  139.             SF-TOGGLE     _"Flatten Image" TRUE)
  140.